//
// Created by isabella on 25-5-26.
//


#include "json.hpp"
#include <common.h>

class Solution {
public:
    vector<int> productExceptSelf(vector<int> &nums) {
        int len = nums.size();
        vector<int> result(len);
        for (int i = 0; i < len; i++) {
            if (i == 0) {
                result[i] = 1;
            } else {
                result[i] = result[i - 1] * nums[i - 1];
            }
        }
        int tmp=1;
        for (int i = len - 1; i >= 0; i--) {
            result[i] = result[i] * tmp;
            tmp *= nums[i];
        }
        return result;
    }
};

int main() {
    auto sp = new Solution();
    vector nums = {1, 2, 3, 4};
    auto r = sp->productExceptSelf(nums);
    nlohmann::json j;
    j["result"] = r;
    cout << j.dump() << endl;
    return 0;
}
